package com.aramis.mydytt.ui.recommend.adapter

import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.aramis.mydytt.R
import com.aramis.mydytt.ui.base.BaseViewHolder
import com.aramis.mydytt.ui.base.SimpleRecyclerAdapter
import com.aramis.mydytt.ui.bean.MovieItemBean
import com.aramis.mydytt.ui.bean.MovieItemWrapperBean
import com.aramis.mydytt.ui.common.CommonMovieItemAdapter

/**
 * Description: MainRecommendAdapter
 * @author lizhidan
 * Created: 2021/4/7
 */
class MainRecommendAdapter : SimpleRecyclerAdapter<MovieItemWrapperBean, MainRecommendAdapter.ViewHolder>() {
    var onSubItemClickListener: ((MovieItemBean) -> Unit)? = null

    class ViewHolder(parent: ViewGroup, var onItemClickListener: ((MovieItemBean) -> Unit)?) :
        BaseViewHolder<MovieItemWrapperBean>(parent, R.layout.item_main_recommend) {
        private val titleView: TextView = itemView.findViewById(R.id.text_item_title)
        private val subListView: RecyclerView = itemView.findViewById(R.id.list_item)
        private val subListAdapter = CommonMovieItemAdapter()

        init {
            subListAdapter.onItemClickListener = onItemClickListener
            subListView.adapter = subListAdapter
            subListView.layoutManager = LinearLayoutManager(subListView.context, LinearLayoutManager.HORIZONTAL, false)
        }

        override fun bind(m: MovieItemWrapperBean, position: Int) {
            titleView.text = m.title
            subListAdapter.setData(m.video)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(parent, onSubItemClickListener)
    }
}